<?php
/**
 * 
 * 
 * @version $Id: Nav.php 440 2012-09-02 03:47:50Z linsir123 $
 */
class Nav 
{
	/**
	 * 导航列表 - 头部
	 */
	static function header($params = null)
	{
		$tmp = null;
		$format = lpUrl::__('goto/channel/%s');
		$navs = App::O('_nav.header');
		
		///
		foreach ($navs as $key => $v) 
			$tmp .= '<a target="_blank" href="'. 
				sprintf($format, $key) .'">'. 
				$v[0] .'</a>';
				
		///
		return '<div class="right">频道推荐：'. $tmp .'</div>';
	}
	
	/**
	 * 导航列表 - 一级
	 */
	static function top($params = null)
	{
		$tmp = null;
		$menu = isset($params['menu']) ? trim($params['menu']) : '';
		
		///
		$navs = App::O('_nav.top');
		foreach ($navs as $title => $nav) {
			$href = lpUrl::__($nav['r']);
			$hover = in_array($menu, $nav['hover']) ? 'class="navhover"' : '';
			$tmp .= '<li '. $hover .'><a href="'. $href .'" title="'. $title .'">'. $title .'</a></li><li class="space"></li>';
		}
		return $tmp;
	}
	
	/**
	 * 导航列表 - 二级
	 */
	static function sub($params = null)
	{
		$mNav = M::nav();
		
		///
		$tmp = null;
		$cId = intval($params['cid']);
		$nav = $mNav->getOne($cId);
		if ($nav['pid'] == 0) 
			$navs = $mNav->getSub($cId);
		else 
			$navs = $mNav->getSub($nav['pid']);
			
		///
		foreach ($navs as $id => $title) {
			$href = Route::urlClass(array('cid'=>$id));
			$hover = $cId == $id ? 'class="submenu_cur"' : '';
			$tmp .= '<a '. $hover .' href="'. $href .'" title="'. $title .'">'. $title .'</a>';
		}
		
		///
		if ($tmp) 
			return '<div id="Submenu" class="content clearfix">'. $tmp .'</div>';
		else 
			return ;
	}
	
	/**
	 * 
	 */
	public function tmallBrandSub($params = null)
	{
		$mNav = M::nav();
		
		///
		$tmp = null;
		$cId = intval($params['cid']);
		$navs = $mNav->getTmallAll();
		
		///
		foreach ($navs as $id => $v) {
			$title = $v['title'];
			$pinyin = $v['pinyin'];
			$hover = $cId == $id ? 'class="submenu_cur"' : '';
			$href = Route::urlTmall(array('cid'=>$id, 'pinyin'=>$pinyin, 'type'=>'brand'));
			$tmp .= '<a '.$hover.' href="'.$href.'" title="'.$title.'">'.$title.'</a>';
		}
		
		///
		if ($tmp) 
			return '<div id="Submenu" class="content clearfix">'.$tmp.'</div>';
		else 
			return ;
	}
	
	
	/// 以下为私有方法 ///
	
	
	
}
